/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-10     xu       the first version
 */
#ifndef APPLICATIONS_CHINESE_DATE_API_H_
#define APPLICATIONS_CHINESE_DATE_API_H_

#include <rtdef.h>
#include <stdint.h>
#include <time.h>

struct chinese_date {
    const char* date;
    const char* lunardate;
    // const char* festival;
    // const char* lunar_festival;
    // const char* fitness;
    // const char* taboo;
    // const char* lunarmonth;
    // const char* lunarday;
    // const char* jieqi;
};

typedef struct chinese_date* chinese_date_t;

/**
 * @brief Query chinese date with HTTP request
 *
 * @param request_tm current time
 * @return chinese_date_t chinese date object
 */
chinese_date_t chinese_date_get(const struct tm* request_tm);

/**
 * @brief delete chinse date object
 *
 * @param date chinse date object
 */
void chinese_date_delete(chinese_date_t date);

/**
 * @brief convert chinse date object to json string
 *
 * @param date chinse date object
 * @return const char* json string, caller need to free
 */
const char* chinese_date_to_json(chinese_date_t date);

/**
 * @brief convert json string to chinese date object
 *
 * @param text json string
 * @return chinese_date_t chinse date object, caller need to delete by chinese_date_delete
 */
chinese_date_t chinese_date_from_json(const char* text);

/**
 * @brief Get chinese date object from kvdb
 *
 * @param request_tm
 * @return chinese_date_t chinse date object, caller need to delete by chinese_date_delete
 */
chinese_date_t chinese_date_kvdb_get(const struct tm* request_tm);

/**
 * @brief Set chinese date object to kvdb
 *
 * @param request_tm current time, will use today date string as key
 * @param cn_date chinese date object
 * @return rt_bool_t return RT_TRUE when success
 */
rt_bool_t chinese_date_kvdb_set(const struct tm* request_tm, chinese_date_t cn_date);

#endif /* APPLICATIONS_CHINESE_DATE_API_H_ */
